//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.exam;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.exam.service.LiveExamJudgeService;
import com.ruoyi.live.base.domain.LiveExam;
import com.ruoyi.live.base.domain.LiveExamJudge;
import com.ruoyi.live.tool.utils.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping({"/exam"})
public class LiveExamJudgeController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(LiveExamJudgeController.class);
    @Autowired
    LiveExamJudgeService service;

    public LiveExamJudgeController() {
    }

    @RequestMapping({"/LiveExamJudgeController/index"})
    public ModelAndView index() {
        LiveExam exam = this.service.getExam();
        return (new ModelAndView("exam/live_exam_judge_list")).addObject("exam", exam).addObject("groups", this.service.getGroups(exam.getId()));
    }

    @RequestMapping({"/LiveExamJudgeController/score"})
    public ModelAndView score() {
        LiveExam exam = this.service.getExam();
        return (new ModelAndView("exam/live_exam_score_list")).addObject("exam", exam).addObject("groups", this.service.getGroups(exam.getId()));
    }

    @RequestMapping({"/LiveExamJudgeController/expert"})
    public ModelAndView expert() {
        return (new ModelAndView("exam/live_exam_judge_form")).addObject("experts", this.service.getExperts());
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/query"})
    public TableDataInfo query(LiveExamJudge entity, HttpServletRequest request) {
        this.startPage();
        List<LiveExamJudge> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/csh"})
    public Message csh() {
        try {
            this.service.doCsh();
            return new Message(true, "");
        } catch (Exception var2) {
            var2.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/queryUserCount"})
    public Message queryUserCount(Long id) {
        try {
            return new Message(true, this.service.queryUserCount(id) + "");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/createExpert"})
    public Message createExpert(Long examId, Integer userGroupCount, Integer userPc, Integer judgePc) {
        try {
            this.service.doCreateExpert(examId, userGroupCount, userPc, judgePc);
            return new Message(true, "分配成功");
        } catch (Exception var6) {
            var6.printStackTrace();
            return new Message(false, "分配失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/add"})
    public Message add(LiveExamJudge entity) {
        try {
            this.service.addLiveExamJudge(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "新增失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/update"})
    public Message update(LiveExamJudge entity) {
        try {
            this.service.updateLiveExamJudge(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "修改失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveExamJudgeController/delete"})
    public Message delete(String id) {
        try {
            this.service.deleteLiveExamJudge(id.split(","));
            return new Message(true, "删除成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "删除失败");
        }
    }

    @RequestMapping({"/LiveExamJudgeController/view"})
    public ModelAndView view(Long id, String page) {
        ModelAndView mv = new ModelAndView("exam/" + page);
        if (id != null) {
            try {
                mv.addObject("entity", this.service.getLiveExamJudge(id));
            } catch (Exception var5) {
                return (new ModelAndView("error")).addObject("tip", var5.getMessage());
            }
        }

        return mv;
    }
}
